// pages/shareFriends/index.js
const {
  get
} = getApp();
Page({
  data: {
    code: ""
  },
  // 初始化加载
  onLoad: function (options) {
    get("/spread/invitation").then(res => {
      if (res.result == 1) {
        this.setData({
          code: res.data
        })
      }
    })
  },
  // 复制
  copyData() {
    wx.setClipboardData({
      data: this.data.code,
      success(res) {
        wx.getClipboardData({
          success(res) {
            console.log(res.data)
          }
        })
      }
    })
  },
  // 分享
  onShareAppMessage: function () {
    return {
      title: "分享到登录页面直接注册登录",
      path: `/pages/login/index?code=${this.data.code}`,
      success: function (res) {
        console.log("分享成功:" + JSON.stringify(res));
      },
      fail: function (res) {
        console.log("分享失败:" + JSON.stringify(res));
      }
    }
  },
  onShow: function () {
    // 控制分享按钮
    wx.showShareMenu({
      withShareTicket: true,
      menus: ['shareAppMessage', 'shareTimeline'],
      success(res) {
        console.log('showShareMenu', res);
      }
    });
  }
})